package misp_backend.controller;



import misp_backend.config.AjaxResult;
import misp_backend.domain.SysOss;
import misp_backend.service.FileService;
import misp_backend.service.SysOssService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;


/**
 * (SysOss)表控制层
 *
 * @author makejava
 * @since 2025-05-10 17:20:45
 */
@RestController
@RequestMapping("/sysoss")
public class SysOssController {
    /**
     * 服务对象
     */
    @Autowired
    private SysOssService sysOssService;
    @Autowired
    private FileService fileService;

    /**
     * 分页查询
     *
     * @param sysOss 筛选条件

     * @return 查询结果
     */
    @GetMapping("/list")
    public ResponseEntity<List<SysOss>> queryByPage(SysOss sysOss) {
        return ResponseEntity.ok(this.sysOssService.queryAllByLimit(sysOss));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("{id}")
    public ResponseEntity<SysOss> queryById(@PathVariable("id") Long id) {
        return ResponseEntity.ok(this.sysOssService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param sysOss 实体
     * @return 新增结果
     */
    @PostMapping
    public ResponseEntity<SysOss> add(SysOss sysOss) {
        return ResponseEntity.ok(this.sysOssService.insert(sysOss));
    }

    /**
     * 编辑数据
     *
     * @param sysOss 实体
     * @return 编辑结果
     */
    @PutMapping
    public ResponseEntity<SysOss> edit(SysOss sysOss) {
        return ResponseEntity.ok(this.sysOssService.update(sysOss));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @DeleteMapping
    public ResponseEntity<Boolean> deleteById(Long id) {
        return ResponseEntity.ok(this.sysOssService.deleteById(id));
    }
@PostMapping("/upload")
    public AjaxResult uploadfile(@RequestParam MultipartFile file,@RequestParam Long dishId){
        return AjaxResult.success(fileService.uploadFile(file,dishId));
}

}

